package ink.yuanchu.picachoframework.controller;


import ink.yuanchu.picachoframework.message.ResultBody;
import ink.yuanchu.picachoframework.service.RoleAssociatedPermissionsService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;

import org.springframework.web.bind.annotation.RestController;

import java.util.Map;

/**
 * <p>
 *  前端控制器
 * </p>
 *
 * @author ziyuan
 * @since 2021-03-19
 */
@RestController
@RequestMapping("/picachoframework/role-associated-permissions")
public class RoleAssociatedPermissionsController {

    @Autowired
    private RoleAssociatedPermissionsService roleAssociatedPermissionsService;

    /**
     * 根据角色id和权限id  删除  这个角色的某个权限
     * @param map
     * @return
     */
    @PostMapping("/deleteByRoleIdAndPermissionsId")
    public ResultBody deleteByRoleIdAndPermissionsId(@RequestBody Map map){
        String roleId = map.get("roleId").toString();
        String permissionsId = map.get("id").toString();
        int count = roleAssociatedPermissionsService.deleteByRoleIdAndPermissionsId(roleId, permissionsId);
        return ResultBody.success(count);
    }

    /**
     * 添加角色权限
     * @param map
     * @return
     */
    @PostMapping("/addRoleAssociatedPermissions")
    public ResultBody addRoleAssociatedPermissions(@RequestBody Map map){
        String roleId = map.get("roleId").toString();
        String permissionsId = map.get("id").toString();
        int count = roleAssociatedPermissionsService.addRoleAssociatedPermissions(roleId, permissionsId);
        return ResultBody.success(count);
    }
}

